<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>软件详情_frm</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../css/news_detail.css"/>
	<style>
		#info h2 {
			font-weight: 300;
		}
	</style>
</head>
<body>
	<div class="aui-content">
        <div id="main">
                <h1 id="title"></h1>
                <label></label>
            	<div id="content" class="TextContent">

            	</div>
        </div>
	</div>
	
	<div class="aui-content aui-content-padded" id="info">
	</div>
	
	<div class="aui-content aui-content-padded" style="padding-bottom: 20px" id="infoUrl">
	</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/OSChinaApi.js" ></script>
<script type="text/javascript" src="../script/common.js" ></script>
<script type="text/javascript">
	var pageParam, imageUrls, img_index;
	apiready = function(){
		pageParam = api.pageParam;
		getDetail( pageParam.ident );
	};
	
	function getDetail( ident ){
		api.showProgress({
		    style: 'default',
		    animationType: 'fade',
		    title: '加载中...',
		    text: '',
		    modal: true
		});
	
		imageUrls = [];
		img_index = 0;
		
		var url = OpenAPI.software_detail + '?ident=' + ident;
		api.ajax({
		    url: url,
		    method: 'get',
		    timeout: 30,
		    dataType: 'text',
		    returnAll:false,
		},function(ret,err){
			api.hideProgress();
		    if (ret) {
				var trans = api.require('trans');
				trans.parse({
				    data:ret
				},function(ret,err){
				    if(ret) {
				    
				    	// 设置 win 的收藏图标状态
						api.execScript({
						    name: 'software_detail_win',
						    script: 'set_favorite_ico( '+ret.oschina.software.favorite+', '+ret.oschina.software.id+' );  set_softwarecomment_button( '+ret.oschina.software.id+', '+ret.oschina.software.tweetCount+' );'
						});
				    
				    	// 把各个内容添加到页面中
				    	var logo = '../image/sofrwareLogo.gif';
				    	if( ret.oschina.software.logo.indexOf("default.gif") == -1 ){
				    		logo = ret.oschina.software.logo;
				    	}
				    	logo = '<img src="'+ logo +'" width="30" height="30" style="vertical-align:middle;" />';
				    	$api.html($api.byId('title'), logo+ret.oschina.software.extensionTitle+' '+ret.oschina.software.title);
				    	
				    	var body = strip_tags(ret.oschina.software.body, '<style><img><p><ul><li><ol><table><pre><code><h1><h2><h3>');
				    	
						// 图片浏览处理
						body.replace(/<img.*?src=\"(.*?)\"[^>]*>/ig, function(a, b) {
							if( b.indexOf("plugins/emoticons") < 0 ){
								body = body.replace(a, "<img class='image' onclick='imageBrowser("+img_index+")' src='"+b+"' />");
								imageUrls.push(b);
							    img_index++;
							}else{
								body = body.replace(a, "<img class='emoticons' src='"+b+"' />");
							}
						});
				    	
				    	$api.html($api.byId('content'), body);
				    	
				    	if( parseInt(ret.oschina.software.authorid)>0 ){
							$api.append($api.byId('info'), '<h2><b>软件作者</b> <b style="color: #087221 !important;">'+ret.oschina.software.author+'</font></b>');
				    	}
				    	if( typeof(ret.oschina.software.license) == 'string' && ret.oschina.software.license.length>0 ){
							$api.append($api.byId('info'), '<h2><b>授权协议</b> '+ ret.oschina.software.license +'</h2>');
				    	}
				    	if( typeof(ret.oschina.software.language) == 'string' && ret.oschina.software.language.length>0 ){
							
							$api.append($api.byId('info'), '<h2><b>开发语言</b> '+ ret.oschina.software.language +'</h2>');
				    	}
				    	if( typeof(ret.oschina.software.recordtime) == 'string' && ret.oschina.software.recordtime.length>0 ){
							$api.append($api.byId('info'), '<h2><b>收录时间</b> '+ ret.oschina.software.recordtime +'</h2>');
				    	}
				    	
				    	if( typeof(ret.oschina.software.homepage) == 'string' && ret.oschina.software.homepage.length>0 ){
							$api.append($api.byId('infoUrl'), '<a class="aui-btn aui-btn-primary" tapmode onclick="open_detail( \''+ret.oschina.software.homepage+'\', \'url\' );">软件首页</a> ');
				    	}
				    	if( typeof(ret.oschina.software.document) == 'string' && ret.oschina.software.document.length>0 ){
							$api.append($api.byId('infoUrl'), '<a class="aui-btn aui-btn-primary" tapmode onclick="open_detail( \''+ret.oschina.software.document+'\', \'url\' );">软件文档</a> ');
				    	}
				    	if( typeof(ret.oschina.software.download) == 'string' && ret.oschina.software.download.length>0 ){
							$api.append($api.byId('infoUrl'), '<a class="aui-btn aui-btn-primary" tapmode onclick="open_detail( \''+ret.oschina.software.download+'\', \'url\' );">软件下载</a> ');
				    	}
				    	
				    	
				    	changeContentFontSize();
				    	
				    	setTimeout("api.parseTapmode()", 100);	// 等0.1秒在执行
				    }else{
				        log(err.msg);
				    }
				});
		    }else {
		        log('错误码：'+err.code+'；错误信息：'+err.msg+'网络状态码：'+err.statusCode);
		    	showAjaxErrMsg(err.code);
		    }
		});
	}
	
	// 浏览图片
	function imageBrowser(index){
			if("undefined" == typeof index){
				index = 0;
			}
			var obj = api.require('imageBrowser');
			obj.openImages({
			    imageUrls: imageUrls,
			    showList: false,
			    activeIndex: index
			});
	}

</script>
</html>